<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require_once APPPATH.'/third_party/Twig/Autoloader.php';
Twig_Autoloader::register();

class Twig_wrapper {
    var $loader;
    var $twig;
    
    public function __construct($twig_config = array())
    {
        //设置模板目录
        $this->loader = new Twig_Loader_Filesystem(APPPATH.'/views/twig_templates');
        //设置缓存目录
        $use_cache = isset($twig_config['use_cache']) ? $twig_config['use_cache'] : false;
        $cache_path = $use_cache ? APPPATH.'cache/compilation_cache' : false;
        $this->twig = new Twig_Environment($this->loader, array(
            'cache' => $cache_path
        ));
        //其他设置
    }
    
    public function parse($template, $data, $return = FALSE)
    {
        if ($data == null) $data = array();
        $html = $this->twig->render($template, $data);
        if ($return) return $html;
        echo $html;
        return null;
    }
}

/* End of file Twig_wrapper.php */
/* Location: ./application/libraries/Twig_wrapper.php */